<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php
	if($user->getLevel() == 6)
	{ echo $commander->getListCommandsPanel('n-sa-a-d-del-pager', ''); }
	else
	{ echo $commander->getListCommandsPanel('sa-pager', ''); }
?>
<div class="menu_list">
	<table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
        <thead class="fields">
            <tr>
                <th class="first center">&nbsp;&nbsp;Id&nbsp;&nbsp;</th>
                <th class="nosort"><input title="<?php echo ucfirst($txt->getWord('all')); ?>" class="select_all" type="checkbox" name="select_all" value="" /></th>
                <th><?php echo ucfirst($txt->getWord('name')); ?></th>
                <th><?php echo ucfirst($txt->getWord('active')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('edit')); ?></th>
                <th class="last nosort"><?php echo ucfirst($txt->getWord('delete')); ?></th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>
<div id="add_dialog" title="<?php echo ucfirst($txt->getWord('new').' '.$txt->getWord('user_level')); ?>?" style="display:none; text-align:left;">
	<p>
		<?php echo ucfirst($txt->getWord('title')); ?>
		<input class="small" name="new_item_title" type="text" value="" maxlength="80" id="new_item_title" /><br />
	</p>
</div>
<div id="delete_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('user_level')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete')); ?></p>
</div>
<script type="text/javascript">
function addNewDialog(itemId)
{
	jQuery('#add_dialog').dialog('open');
	jQuery('#add_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('cancel')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('add')).' '.$txt->getWord('element'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&list=level", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					new_item_title: jQuery('#new_item_title').val()} 
				).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function deleteDialog(itemId)
{
	jQuery('#delete_dialog').dialog('open');
	jQuery('#delete_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete')).' '.$txt->getWord('element'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&list=<?php echo $_GET['list']; ?>", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					del_item_id: itemId} 
				).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function loadItems()
{
	jQuery('table.item_list tbody').empty();
	jQuery('table.item_list tbody').html('<?php echo $commander->getComponentListLoading(); ?>'); 
	jQuery.ajax(
	{
		url: "ajax.php?con=<?php echo $_GET['con']; ?>&list=<?php echo $_GET['list']; ?>",
		cache: false,
	  	success: function(html)
	  	{ 
			jQuery('table.item_list tr.loading').remove();
			jQuery("table.item_list tbody").append(html); 
			jQuery("#menulist").addClass('tablesorter');
			jQuery("#menulist").tablesorter(
				{
					widthFixed: true,  
					headers: { 0: { sorter: 'numeric' }, 1: { sorter: false}, 5: {sorter: false}, 6: {sorter: false} }, 
					sortList: [[0,0]],
					textExtraction: function(node) { return node.innerHTML; }
				}).tablesorterPager(
				{
					container: jQuery("div.pager")
				}).tablesorterFilter(
				{
					filterContainer: $("#filter-box"),
					filterClearContainer: $("#filter-clear-button"),
					filterWaitTime: 100,
					filterColumns: [1],
					filterCaseSensitive: false
				});
		}
	});
}

jQuery(document).ready(function() 
{ loadItems(); });
</script>

